package com.biboheart.adapter.express.support;

import com.biboheart.adapter.express.operation.Calculate;
import com.biboheart.adapter.support.utils.ObjectTypeUtils;

import java.math.BigDecimal;

public class AdditionCalculate implements Calculate<Number, Number, Number> {
    @Override
    public Number calc(Number left, Number right) {
        if (null == left) {
            left = 0;
        }
        if (null == right) {
            return left;
        }
        if ((left instanceof Double) || (right instanceof Double)) {
            return BigDecimal.valueOf(ObjectTypeUtils.convertType(left, Double.class)).add(BigDecimal.valueOf(ObjectTypeUtils.convertType(right, Double.class))).doubleValue();
        }
        if ((left instanceof Float) || (right instanceof Float)) {
            return BigDecimal.valueOf(ObjectTypeUtils.convertType(left, Float.class)).add(BigDecimal.valueOf(ObjectTypeUtils.convertType(right, Float.class))).floatValue();
        }
        if ((left instanceof Long) || (right instanceof Long)) {
            return BigDecimal.valueOf(ObjectTypeUtils.convertType(left, Long.class)).add(BigDecimal.valueOf(ObjectTypeUtils.convertType(right, Long.class))).longValue();
        }
        return BigDecimal.valueOf(ObjectTypeUtils.convertType(left, Integer.class)).add(BigDecimal.valueOf(ObjectTypeUtils.convertType(right, Integer.class))).intValue();
    }

    @Override
    public Number calc(Number num) {
        return null;
    }
}
